package com.hcms.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.hcms.mybatis.entity.SysAdminLog;
import com.hcms.admin.service.ISysAdminLogService;
import com.hcms.mybatis.mapper.SysAdminLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 后台用户登录日志表 服务实现类
 * </p>
 *
 * @author achenxw@126.com
 * @since 2023-02-13
 */
@Service
public class SysAdminLogServiceImpl extends ServiceImpl<SysAdminLogMapper, SysAdminLog> implements ISysAdminLogService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysAdminLogMapper sysAdminLogMapper;

    @Override
    public List<SysAdminLog> getList(String username, String method, String address, Integer pageNum, Integer pageSize) {
        logger.info("Run getList(), pageNum={}, pageSize={}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize, "id DESC");
        LambdaQueryWrapper<SysAdminLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrUtil.isNotEmpty(username), SysAdminLog::getUsername, username);
        queryWrapper.eq(StrUtil.isNotEmpty(method), SysAdminLog::getMethod, method);
        queryWrapper.like(StrUtil.isNotEmpty(address), SysAdminLog::getAddress, address);
        return sysAdminLogMapper.selectList(queryWrapper);
    }

    @Override
    public SysAdminLog getView(Long id) {
        return sysAdminLogMapper.selectById(id);
    }
}
